/* global $*/

exports.toastNormal = function(message, duration) {
    toast(message, "toast-normal", duration)
}

exports.toastSuccess = function(message, duration) {
    toast(message, "toast-success", duration)
}

exports.toastWarning = function(message, duration = 3800) {
    toast(message, "toast-warning", duration)
}

exports.toastError = function(message, duration = 3800) {
    toast(message, "toast-error", duration)
}

function toast(message, extraClass, duration = 2000) {
    let $t = $("<div>", {class: "toast " + extraClass, html: message})
        .appendTo($(".toast-box"))
        .hide().slideDown(200)

    setTimeout(function() {
        $t.slideUp(200, () => $t.remove())
    }, duration)
}
